package com.yc.cinema;

import com.yc.cinema.biz.HallBiz;
import com.yc.cinema.biz.UserBiz;
import com.yc.cinema.dao.HallDao;
import com.yc.cinema.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;

//@Configuration  // beans.xml
public class IocConfig {

    @Bean(name = "userBiz",
    initMethod = "init",
    destroyMethod = "destroy",
    autowire = Autowire.BY_NAME)  // <bean ...>
    @Scope("prototype")
    UserBiz userBiz(){
        final UserBiz userBiz = new UserBiz(18);
        userBiz.setName("张三");
        return userBiz;
    }

    @Bean(initMethod = "init", destroyMethod = "destroy")
    @Lazy
    HallBiz hallBiz(){
        return new HallBiz();
    }

    // 方法名即 id
    @Bean
    UserDao udao(){
        return new UserDao();
    }

    @Bean
    HallDao hallDao(){
        return new HallDao();
    }

}
